home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2024 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.7 KB

  1. Path: dawn.mmm.com!news
  2. From: kjhopps@mmm.com (Kevin J Hopps)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: On Exception handling.....from a newbie
  5. Date: 15 Jan 1996 14:50:25 GMT
  6. Organization: 3M - St. Paul, MN  55144-1000 US
  7. Message-ID: <4ddpjh$3au@dawn.mmm.com>
  8. References: <1996Jan15.013336.4730@sfov1.verifone.com>
  9. Reply-To: kjhopps@mmm.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. khemani_p1@hnlv4.verifone.com wrote:
  13.  
  14.  
  15.  
  16. > I want to know how do I retry a try block which has thrown a exception. Is 
  17. > there some neat of doing this in C++ ?
  18.  
  19. You can always put the try block inside a loop...
  20.  
  21. > For eg.
  22.  
  23. > try {
  24. >      open file;
  25. >     read the blocks;
  26. >     ...
  27. >     } catch (OpenFileException e)
  28. >     {
  29. >     retry (how?)
  30. >     }
  31. >       catch (ReadFileException e)
  32. >     {
  33. >     close file;
  34. >     retry (?)
  35. >     }
  36.  
  37. How about this?
  38.     bool retry = true;
  39.     while (retry) {
  40.     AutoFileCloser autoCloser;
  41.     try {
  42.         open file;
  43.         autoCloser.manage(something); // give "handle" to autoCloser
  44.         read the blocks;
  45.         retry = false;
  46.     } catch (OpenFileException e) {
  47.     } catch (ReadFileException e) {
  48.     }
  49.     // autoCloser closes file here, if necessary
  50.     }
  51.  
  52. > Please send the reply to khemani_p1@verifone.com
  53.  
  54. Unless you promise to post a summary, read your replies here.  People
  55. read your article because it sounds interesting.  They deserve to read
  56. the replies too.
  57. --
  58. Kevin J. Hopps                  e-mail: kjhopps@mmm.com
  59. 3M Company                      phone:  (612) 737-4643
  60. 3M Center, Bldg. 235-2D-57      fax:    (612) 737-2700
  61. St. Paul, MN 55144-1000         Opinions are my own.  I don't speak for 3M.
  62.     But 3M speaks for me -- I did not write the following line:
  63.  
  64. Opinions expressed herein are my own and may not represent those of 3M.
  65.